package com.zhr.tea.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhr.tea.R;
import com.zhr.tea.entity.shouye.Wangqi;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ym on 2016/11/6.
 */

public class ShouyeJingcaiAdapter extends RecyclerView.Adapter<ShouyeJingcaiAdapter.ViewHolder> {
    private List<Wangqi.ContentBean> data;
    private Context context;

    public ShouyeJingcaiAdapter(Context context, List<Wangqi.ContentBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_shou_wangqi, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tvGototitle.setText(data.get(position).getGotoTitle());
        holder.tvThemetime.setText(data.get(position).getThemeTime().substring(0, data.get(position).getThemeTime().indexOf(" ")));
        Glide.with(context).load(data.get(position).getThemePhoto()).placeholder(R.mipmap.diy_bg).into(holder.ivPhoto);
    }


    @Override
    public int getItemCount() {
        return data.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_gototitle)
        TextView tvGototitle;
        @BindView(R.id.tv_themetime)
        TextView tvThemetime;
        @BindView(R.id.iv_photo)
        ImageView ivPhoto;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
